package com.itcast.googleplay.holder;

import com.itcast.googleplay.R;
import com.itcast.googleplay.domain.SubjectBean;
import com.itcast.googleplay.http.CZApi;
import com.itcast.googleplay.utils.UIUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class SubjectHolder extends BaseHolder<SubjectBean>{

	private TextView tvDes;
	private ImageView ivImage;
	private DisplayImageOptions options;

	@Override
	public void initData() {
		SubjectBean bean = getData();
		tvDes.setText(bean.des);
		//ImageLoader
		//初始图片缓存方式代码
		options = new DisplayImageOptions.Builder()
				.showImageOnLoading(R.drawable.ic_default)//在加载图片的时候,展示的默认图片
				
				.showImageForEmptyUri(R.drawable.ic_default)//uri传递出现问题时展示的图片
				
				.showImageOnFail(R.drawable.ic_default)//加载网络失败的时候,展示的图片
				
				.bitmapConfig(Bitmap.Config.RGB_565)
				
				.cacheInMemory(true)//是否需要内存缓存
				
				.cacheOnDisk(true)//是否需要磁盘缓存
				
				.considerExifParams(true)//是否支持图片自动调整,让其正常图像显示
		
				.build();//设置圆角半径
		
		ImageLoader.getInstance().displayImage(CZApi.BASEIMGURL+bean.url, ivImage, options);
	}

	@Override
	public View initView() {
		View view = UIUtils.inflate(R.layout.layout_subject_item);
		tvDes = (TextView) view.findViewById(R.id.tv_des);
		ivImage = (ImageView) view.findViewById(R.id.iv_image);
		return view;
	}

}
